﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace jmwqz
{
    public partial class userlist : System.Web.UI.Page
    {
        protected int totalCount;
        protected int page;
        protected int pageSize;
        Maticsoft.BLL.tb_userdata buser = new Maticsoft.BLL.tb_userdata();
        protected string keywords = string.Empty;
        protected string minjifen = string.Empty;
        protected string maxjifen = string.Empty;
        string st5r = "";
        protected void Page_Load(object sender, EventArgs e)
        {
            page = Maticsoft.Common.MXRequest.GetQueryIntValue("page", 1);
            minjifen = Maticsoft.Common.MXRequest.GetQueryString("minjifen");
            maxjifen = Maticsoft.Common.MXRequest.GetQueryString("maxjifen");

            if (!IsPostBack)
            {
                if (!string.IsNullOrWhiteSpace(minjifen))
                {
                    st5r += " jifen >= " + minjifen + " ";
                    if (!string.IsNullOrWhiteSpace(maxjifen))
                    {
                        st5r += " and jifen <= " + maxjifen + " ";
                    }
                }
                else
                {
                    if (!string.IsNullOrWhiteSpace(maxjifen))
                    {
                        st5r += " jifen <= " + maxjifen + " ";
                    }
                }
                totalCount = buser.GetRecordCount(st5r);
                pageSize = 20;

                RptBind();
                Txmin.Text = minjifen;
                Txmax.Text = maxjifen;
            }

        }

        #region 数据绑定=================================
        private void RptBind()
        {
            try
            {
                DataSet ds = buser.GetListByPage(st5r , " ", this.pageSize, this.page);

                this.rptList.DataSource = ds;
                this.rptList.DataBind();

                //绑定页码
                txtPageNum.Text = this.pageSize.ToString();
                string pageUrl = Maticsoft.Common.Utils.CombUrlTxt("userlist.aspx", "keywords={0}&page={1}&minjifen={2}&maxjifen={3}",
                    this.keywords, "__id__", minjifen, maxjifen);
                PageContent.InnerHtml = Maticsoft.Common.Utils.OutPageList(this.pageSize, this.page, this.totalCount, pageUrl, 8);
            }
            catch 
            {

            }

        }
        #endregion

        //设置分页数量
        protected void txtPageNum_TextChanged(object sender, EventArgs e)
        {
            //int _pagesize;
            //if (int.TryParse(txtPageNum.Text.Trim(), out _pagesize))
            //{
            //    if (_pagesize > 0)
            //    {
            //        Maticsoft.Common.Utils.WriteCookie("user_list_page_size", _pagesize.ToString(), 14400);
            //    }
            //}
            //Response.Redirect(Maticsoft.Common.Utils.CombUrlTxt("userlist.aspx", "keywords={0}",this.keywords));
        }

        //批量删除
        protected void btnDelete_Click(object sender, EventArgs e)
        {
            int sucCount = 0;
            int errorCount = 0;
            for (int i = 0; i < rptList.Items.Count; i++)
            {
                int id = Convert.ToInt32(((HiddenField)rptList.Items[i].FindControl("hidId")).Value);
                CheckBox cb = (CheckBox)rptList.Items[i].FindControl("chkId");
                if (cb.Checked)
                {
                    if (buser.Delete(id))
                    {
                        sucCount += 1;
                    }
                    else
                    {
                        errorCount += 1;
                    }
                }
            }
            JscriptMsg("删除成功" + sucCount + "条，失败" + errorCount + "条！",
                Maticsoft.Common.Utils.CombUrlTxt("userlist.aspx", "keywords={0}&minjifen={2}&maxjifen={3}", this.keywords, minjifen, maxjifen), "Success");
        }

        protected void JscriptMsg(string msgtitle, string url, string msgcss)
        {
            string msbox = "parent.jsprint(\"" + msgtitle + "\", \"" + url + "\", \"" + msgcss + "\")";
            ClientScript.RegisterClientScriptBlock(Page.GetType(), "JsPrint", msbox, true);
        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            minjifen = Txmin.Text.Trim();
            maxjifen = Txmax.Text.Trim();
            Response.Redirect(Maticsoft.Common.Utils.CombUrlTxt("userlist.aspx", "keywords={0}&minjifen={1}&maxjifen={2}", this.keywords, minjifen, maxjifen));
        }
    }
}